

class CCpuFactory;

void RegisterCPUFactory(CCpuFactory* factory);
ICpu* CPUFactory (const char* type);
void OutputCPUList();

typedef ICpu*(*CpuInterfaceInitcall)();
class CCpuFactory {
	private:
		CpuInterfaceInitcall InitCall;
		const char* name;
		const char* description;
		int interfaceversion;

	public:
		CCpuFactory(const char* name, int intf_version, CpuInterfaceInitcall initcall) {
				this->name = name;
				this->interfaceversion = intf_version;
				this->InitCall = initcall;

				RegisterCPUFactory(this);
		}

		const char* GetName() { return this->name; }
		const char* GetDescription() { return this->description; }

		int GetInterfaceVersion() { return this->interfaceversion; }
		
		ICpu* Init() { return InitCall(); }
};

#define CPU_FACTORY(name,version,class)\
ICpu* class##_Factory() {\
		return new class;\
}\
CCpuFactory class##factory(name,version,class##_Factory);

#define CPU_FACTORY_ALIAS(name,version,aliasname,realname)\
	ICpu* aliasname##_Factory() {\
		return new realname;\
}\
CCpuFactory class##factory(name,version,aliasname##_Factory);
